# 设计一个类
# class Student:
#     name = None         # 记录学生姓名
#     gender = None       # 记录学生性别
#     nationality = None  # 记录学生国籍
#     native_place = None # 记录学生籍贯
#     age = None          # 记录学生年纪
#
#
# # 创建一个对象
# stu1 = Student()
#
# # 赋值
# stu1.name = "张三"
# stu1.gender = "男"
# stu1.nationality = "中国"
# stu1.native_place = "湖南省"
# stu1.age = 18
#
# # 获取对象的信息
# print(stu1.name)
# print(stu1.gender)
# print(stu1.nationality)
# print(stu1.native_place)
# print(stu1.age)
# from traceback import print_list


# 定义一个带有成员方法的类

# class Student:
#     name = None
#
#     def say_hi(self):
#         print(f"Hello, my name is {self.name}")
#
#
# stu = Student()
# stu.name = '小明'
# stu.say_hi()






# 构造方法 __init__

# class Student:
#     def __init__(self,name,age,tel):
#         self.name = name
#         self.age = age
#         self.tel = tel
#         print(f"name: {self.name}, age: {self.age}, tel: {self.tel}")
#
# stu1 = Student('John',23,'123-123-12')






# 字符串方法 __str__

# class Student:
#     def __init__(self,name,age,tel):
#         self.name = name
#         self.age = age
#         self.tel = tel
#
#     def __str__(self):
#         return f"Name: {self.name},Age: {self.age},Tel: {self.tel}"
#
# stu = Student("John",22,"123-123-12")
# print(stu)





# __lt__ 小于符号比较方法

# class Student:
#     def __init__(self,name,age,tel):
#         self.name = name
#         self.age = age
#         self.tel = tel
#
#     def __lt__(self,other):
#         return self.age < other.age
#
#
# stu1 = Student('小明',22,'USA')
# stu2 = Student('小爱',23,'USA')
# print(stu1 < stu2)






# __le__ 小于等于符号比较方法

# class Student:
#     def __init__(self,name,age,tel):
#         self.name = name
#         self.age = age
#         self.tel = tel
#
#     def __le__(self,other):
#         return self.age <= other.age
#
#
# stu1 = Student('John',22,'USA')
# stu2 = Student('John',23,'USA')
# print(stu1 <= stu2)
# print(stu1 >= stu2)





# __eq__ 比较运算符

# class Student:
#     def __init__(self,name,age,tel):
#         self.name = name
#         self.age = age
#         self.tel = tel
#
#     def __eq__(self,other):
#         return self.age == other.age
#
# stu1 = Student('John',23,'123-123-12')
# stu2 = Student('John',23,'123-123-12')
# print(stu1 == stu2)







# 私有成员变量和私有成员方法

# class Phone:
#
#     __current_voltage = 0 # 电压
#
#     def __keep_single_core(self):
#         print("CPU单核模式")
#
#     def call_by_5g(self): # 内部成员可以使用私有成员变量和私有成员方法
#         if self.__current_voltage >= 1:
#             print("5g通话开启")
#
#         else:
#             self.__keep_single_core()
#             print("电量不足，设置单核运行")
#
# phone = Phone()
# # print(phone.__current_voltage)
# # phone.__keep_single_core()
#
# phone.call_by_5g()








# 继承

# class Phone:
#     IMEI = None  # 序列号
#     producer = "HM" # 厂商
#
#     def call_by_4g(self):
#         print("4g")
#
# class Phone2(Phone):
#     face_id = "10001"  # 面部识别
#
#     def call_by_5g(self):
#         print("5g")
#
# phone = Phone2()
# phone.call_by_4g()
# phone.call_by_5g()
# print(phone.producer)



# 复写  调用父类重名成员

# class Phone:
#     IMEI = None
#     producer = "HM"
#
#     def call_by_4g(self):
#         print("4g")
#
# class Phone2(Phone):
#     producer = "IT"
#
#     def call_by_4g(self):
#         print("4g+")
#         print(f"父类的厂商: {Phone.producer}") # 调用父类重名成员
#         Phone.call_by_4g(self)
#         print(f"父类的厂商: {super().producer}")
#         super().call_by_4g()
#
# phone = Phone2()
# phone.call_by_4g()
# print(phone.producer)







# 类型注解

# var1: int = 10
#
#
# class Student:
#     pass
# stu: Student = Student()
#
#
# my_list: list = [1, 2, 3]
# my_list1: list[int] = [1, 2, 3]
#
# my_dict: dict = {'shy':135}
# my_dict1: dict[str,int] = {'shy':135}
#
# print(var1)





# 在注释中进行类型注释

# import random
#
# var1 = random.randint(1,10) # type: int
# print(var1)








# 函数和方法的类型注解

# def add(x: int,y: int):
#     return x + y
# add(1,2)
#
# # 对返回值进行注解
# def func(data: list) -> list:
#     return data






# 使用union联合类型注解

# from typing import Union
#
# my_list: list[Union[int, str]] = [1,2,'shy']
#
# def func(data: Union[int, str]) -> Union[str,int]:
#     pass








# 多态

# class Animal:
#     def speak(self):
#         pass
#
# class Dog(Animal):
#     def speak(self):
#         print("Woof!")
#
# class Cat(Animal):
#     def speak(self):
#         print("Meow!")
#
#
# def make_noise(animal: Animal):
#     animal.speak()
#
#
# dog = Dog()
# cat = Cat()
#
# make_noise(dog)
# make_noise(cat)










